#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/cdev.h>
#include <linux/spi/spi.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_device.h>
#include <linux/of_graph.h>
#include <linux/of_gpio.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
#include <linux/time.h>
#include <linux/timer.h>
#include <linux/skbuff.h>
#include <linux/spinlock.h>
#include <linux/crc32.h>
#include <linux/of_net.h>
#include <linux/ethtool.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/gpio.h>

#include <asm/delay.h>
#include <asm/irq.h>
#include <asm/io.h>

struct port_n{
	unsigned int CFG[4];//配置寄存器
	unsigned int DATA;//数据寄存器
	unsigned int DRV[2];//多驱动寄存器
	unsigned int PUL[2];//端口上下拉寄存器
};//IO配置指针


#define XSS_PIO 0x01C20800 //1*1024
#define GPIO_A	((volatile struct port_n *)(gpio_base+0x24*0))
#define GPIO_B	((volatile struct port_n *)(gpio_base+0x24*1))
#define GPIO_C	((volatile struct port_n *)(gpio_base+0x24*2))
#define GPIO_D	((volatile struct port_n *)(gpio_base+0x24*3))
#define GPIO_E	((volatile struct port_n *)(gpio_base+0x24*4))
#define GPIO_F	((volatile struct port_n *)(gpio_base+0x24*5))
#define GPIO_G	((volatile struct port_n *)(gpio_base+0x24*6))

#define RX_DAT_LEN				0x02	//获取数据长度寄存器
#define TX_BUFF_AVAIL			0x03	//下发数据标志寄存器
#define SPI_INT_HOST_MASK		0x05	//中断配置寄存器
#define SPI_INT_HOST_STTS		0x06	//中断状态寄存器
#define DAT_PORT0				0x00	//数据端口 0
#define DAT_PORT1				0x10	//数据端口 1
#define DN_CMD_PORT0			0x01	//命令端口 0
#define DN_CMD_PORT1			0x11	//命令端口 1

#define Write_reg(x)			(0x80 | (x))
#define Read_reg(x)				((~0x80) & (x))

struct w800_dev
{
	struct device *device;
	struct spi_device *spi;
	struct device_node *nd;
	struct completion ah_done;
	struct completion bh_done;
	struct completion cmd_done;
	struct net_device *w_net;
	struct task_struct *ah_th;
	struct task_struct *bh_th;
	struct sk_buff *skb;
};

void spinet_init(struct w800_dev *w800dev);
void rm_spinet_init(struct w800_dev *w800dev);

static void w800_spiex(struct w800_dev *w800dev,struct spi_transfer *spi_t)
{
	struct spi_message m;

	spi_message_init(&m);
	spi_message_add_tail(spi_t,&m);
	spi_sync(w800dev->spi,&m);
}

extern char mcu_data[128];